﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp1
{
    public static class BaseLearn
    {

        public static int GetMax(int[] arrays) //声明方法
        {
            int max = arrays[0];

            for (int i = 0; i < arrays.Length; i++)
            {
                if (arrays[i] > max)
                {
                    max = arrays[i];
                    continue;
                }
            }
            return max;
        }

        public static void PrimeNumber()
        {
            for (int i = 2; i < 101; i++)
            {
                for (int j = 2; j < i; j++)
                {
                    if (i % j == 0 && i != j)
                    {
                        break;
                    }
                    else if (i % j == 0 && i == j)
                    {
                        Console.WriteLine(i);
                    }//else

                }

            }

        }

        public static int BinarySeek(int[] numbers)
        {

            int target = 45;
            int left = 0,
            right = numbers.Length - 1, 
            middle;
            while (left < right)
            {
                middle = (left + right) / 2;
                if (target < numbers[middle])
                {
                    right = middle - 1;
                }
                else if (target > numbers[middle])
                {
                    left = middle + 1;
                }
                else //if(target == numbers[middle])
                {
                 
                    return numbers[middle];
                }
            }
            return -1;


            //public static double GetMin(int[] arrays)
            // {
            //     return -1;
            // }
            //double[] grade = new double[] { 87, 95, 90, 61, 78, 72 };


        }

        //int[] arrays;
        //private int top = 0;
       
        //public MimicStack(int length)
        //{
        //    arrays = new int[length];
        //}
       
        //public void Push(int element)//截断式编程
        //{
        //    if (top > arrays.Length)
        //    {
        //        Console.WriteLine("stack overflow");
        //    }
        //    else
        //    {
        //        arrays[top] = element;//元素放进栈顶指针指向的位置
        //        top++;
        //    }
        //}

        //public void Push(params int[] elements)//重载
        //{
        //    for (int i = 0; i < elements.Length; i++)
        //    {
        //        Push(elements[i]);
        //    }
        //}
        //public int Pop()
        //{
        //    if (top == 0)
        //    {
        //        Console.WriteLine("The stack is empty");
        //        return -1;
        //    }
        //    else
        //    {
        //        top--;
        //        return arrays[top];

        //    }
        //}
    }
}
